package com.lb.jwitter.action;


import java.util.ArrayList; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.List; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQLDTTXAHocVienPhieuLyLichGiaDinh;
import com.lb.jwitter.service.TblQLDTTXAHocVienPhieuLyLichGiaDinhService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAHocVientblQLDTTXAHocVienPhieuLyLichGiaDinhSearchAction{
    private int pageSize; 
    public void setPageSize(int pageSize) {
       this.pageSize = pageSize;
     }

    public int getPageSize() {
       return pageSize;
 }

    private int page; 
    public void setPage(int page) { this.page = page;   }

    public int getPage() {
       return page;
   }

    private int pages; 
    public void setPages(int pages) { this.pages = pages;   }

    public int getPages() {
       return pages;
     }

    private String dataString; 
    public void setDataString(String dataString) { this.dataString = dataString;    }

    public String getDataString() {
       return dataString;
    }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id ;
   }
    public void setId(int id) {
       this.id = id;
    }

    private int hocVienId; 
    public void setHocVienId(int hocVienId) {
       this.hocVienId = hocVienId;
  }

    public int getHocVienId() {
       return hocVienId;
  }

    private String hoTen; 
    public void setHoTen(String hoTen) {
       this.hoTen = hoTen;
   }

    public String getHoTen() {
       return hoTen;
   }

    private int quanHeId; 
    public void setQuanHeId(int quanHeId) {
       this.quanHeId = quanHeId;
  }

    public int getQuanHeId() {
       return quanHeId;
  }

    private String thuongTru; 
    public void setThuongTru(String thuongTru) {
       this.thuongTru = thuongTru;
   }

    public String getThuongTru() {
       return thuongTru;
   }

    private String ghiChu; 
    public void setGhiChu(String ghiChu) {
       this.ghiChu = ghiChu;
   }

    public String getGhiChu() {
       return ghiChu;
   }

    private List<TblQLDTTXAHocVienPhieuLyLichGiaDinh> tblQLDTTXAHocVienPhieuLyLichGiaDinhs; 
    public List<TblQLDTTXAHocVienPhieuLyLichGiaDinh>  getTblQLDTTXAHocVienPhieuLyLichGiaDinhs() {
        return tblQLDTTXAHocVienPhieuLyLichGiaDinhs; 
      } 

    private TblQLDTTXAHocVienPhieuLyLichGiaDinhService tblQLDTTXAHocVienPhieuLyLichGiaDinhService; 

	private int preSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HocVien_PhieuLyLich_GiaDinh", "xem")){ 
        return "noprivilege"; 
    }        tblQLDTTXAHocVienPhieuLyLichGiaDinhService = (TblQLDTTXAHocVienPhieuLyLichGiaDinhService) context.getBean("tbl_QLDTTXA_HocVien_PhieuLyLich_GiaDinhClient"); 
        msg = new Message(); 
        List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
    if(id != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("id");
        con.setValue1(id);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(hocVienId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("hocVienId.id");
        con.setValue1(new Long(hocVienId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(hoTen != null && !hoTen.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("hoTen");
        con.setValue1(hoTen);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(quanHeId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("quanHeId.id");
        con.setValue1(new Long(quanHeId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(thuongTru != null && !thuongTru.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("thuongTru");
        con.setValue1(thuongTru);
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(ghiChu != null && !ghiChu.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("ghiChu");
        con.setValue1(ghiChu);
        con.setOperator("eq");
        cons.add(con);	
    } 
        preSearch(msg, cons); 
       if (msg.isPreMessage_b()) 
       { 
           if(pageSize == 0){ 
               pageSize = 20; 
           } 
            if(page == 0){ 
               page =1; 
           } 
           tblQLDTTXAHocVienPhieuLyLichGiaDinhs = tblQLDTTXAHocVienPhieuLyLichGiaDinhService.findtblQLDTTXAHocVienPhieuLyLichGiaDinhByCondition(cons,pageSize,page); 
           pages = tblQLDTTXAHocVienPhieuLyLichGiaDinhService.counttblQLDTTXAHocVienPhieuLyLichGiaDinhByCondition(cons)/pageSize + 1; 
           postSearch(msg, cons); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 
      dataString = ""; 
      dataString += "&id=" + id; 
      dataString += "&hocVienId=" + hocVienId; 
      dataString += "&hoTen=" + hoTen; 
      dataString += "&quanHeId=" + quanHeId; 
      dataString += "&thuongTru=" + thuongTru; 
      dataString += "&ghiChu=" + ghiChu; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Seach tbl_QLDTTXA_HocVien_PhieuLyLich_GiaDinh Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
